var mysql = require("mysql");

var pool = mysql.createPool({
    host:"47.110.50.241",
    user:"root",
    password:"zjl60619871204",
    database:"wanlv"
});

function query(sql,callback){
    pool.getConnection(function(err,connection){
        connection.query(sql, function (err,rows) {
            callback(err,rows);
            connection.release();
        });
    });
}

function del(sql, params, callback) {
    pool.getConnection(function(err,connection){
        connection.query(sql, params, function (err,rows) {
            callback(err,rows);
            connection.release();
        });
    });    
}

function insert(sql, params, callback) {
    console.log('insert::', sql);
    console.log('insert params :::', params);
    pool.getConnection(function(err,connection){
        connection.query(sql, params, function (err,rows) {
            console.log('insert:::err::', err);
            console.log('insert:::rows:::', rows);
            callback(err,rows);
            connection.release();
        });
    });
}

function select(sql, params, callback) {
    pool.getConnection(function(err,connection){
        connection.query(sql, params, function (err,rows) {
            callback(err,rows);
            connection.release();
        });
    });
}
const mod = {
    query,
    insert,
    select,
    del,
    update: select
}
// exports.query = query;
module.exports = mod;